require('dot-env');

// 创建实例对象
const vault = require('node-vault')({
  apiVersion: 'v1', // API 版本，默认
  endpoint: 'http://127.0.0.1:8200', // Vault接口地址
});

const roleId = process.env.ROLE_ID;
const secretId = process.env.SECRET_ID;

const run = async () => {
  // 1. AppRole登录，获取Token
  const result = await vault.approleLogin({
    role_id: roleId,
    secret_id: secretId,
  });
  vault.token = result.auth.client_token;

  // 2. 读取配置数据
  const { data } = await vault.read('frfw-api/data/test');
  console.log(data);
};

run();
